home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / pas_0593.zip / FSIZE.PAS < prev    next >
Pascal/Delphi Source File  |  1993-05-30  |  3KB  |  68 lines

  1. {─ Fido Pascal Conference ────────────────────────────────────────────── PASCAL ─
  2. Msg  : 163 of 187
  3. From : BRIAN PAPE                          1:2250/26.0          21 May 93  09:47
  4. To   : ALL
  5. Subj : DOS Fsize...
  6. ────────────────────────────────────────────────────────────────────────────────
  7. All DOS would have needed in 6.0 (unless it is there, I don't buy
  8. Microsloth unless I have to) is this...  I was at work making DOS
  9. "menus" for some new machines that we got in, and I wanted to make them
  10. display ANSI menus if ANSI.SYS was loaded, or regular menus (ASCII) if
  11. not...  I thought about this forever, and finally, as much as I could
  12. come up with was this:  But I didn't have an FSIZE utility, so I whipped
  13. out my trusty copy of TPC along with TURBO.TPL (taking up a grand total
  14. of about 110k) and wrote a little utility to fix it :)    <-- just shows
  15. that TPC and .TPL are all you need sometimes...
  16.  
  17. mem/c|find /i "ANSI">$menu$.tmp fsize $menu$.tmp 1
  18. if errorlevel.........
  19.  
  20. So that if the size of the file $menu$.tmp was equal to or greater than
  21. 1, FSIZE would return errorlevel 2, otherwise errorlevel 1.  Can anyone
  22. think of a way to do this in DOS strictly?  Kind of off-topic, but I did
  23. write a whole 2-minute program :)}
  24.  
  25. program fsize;
  26. uses dos;
  27. var
  28.   f : file;
  29.   s,fname : string;
  30.   code : integer;
  31.   actualsize,ssize : longint;
  32. procedure writehelp;
  33. begin
  34.   writeln('FSize utility, Copyright 1993 Alphawave Technologies');
  35.   writeln('usage:');
  36.   writeln('  FSize filename [minsize]');
  37.   writeln('Where filename is the file to check the filesize of.');
  38.   writeln('If minsize is omitted, it is assumed to be 1.  Filesize will');
  39.   writeln('return an errorlevel of 2 if the file is the size of minsize or');
  40.   writeln('greater, an errorlevel of 1 if the file size is smaller than');
  41.   writeln('minsize, and an errorlevel of 0 if this help screen appears.');
  42.   halt(0);
  43. end;  { writehelp }
  44. begin
  45.   if paramcount = 0 then
  46.     writehelp
  47.   else
  48.     fname := paramstr(1);
  49.   assign(f,fname);
  50.   {$i-} reset(f); {$I+}
  51.   if ioresult <> 0 then
  52.     writehelp;
  53.   if paramcount = 1 then
  54.     ssize := 1
  55.   else
  56.     begin
  57.       s := paramstr(2);
  58.       val(s,ssize,code);
  59.       if code <> 0 then ssize := 1;
  60.     end;  { else }
  61.  
  62.   { If the filesize of F is greater than or equal to the filesize specified
  63.     on the command line, halt with an errorlevel of 2, otherwise an error-
  64.     level of 1 }
  65.   actualsize := filesize(f);
  66.   close(f);
  67.   if actualsize >= ssize then halt(2) else halt(1);
  68. end.  { fsize }